package edu.lingnan.reactproject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.lingnan.reactproject.pojo.Categorys;
import edu.lingnan.reactproject.mapper.CategorysMapper;
import edu.lingnan.reactproject.service.CategorysService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.lingnan.reactproject.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陈世杰
 * @since 2022-01-15
 */
@Service
public class CategorysServiceImpl extends ServiceImpl<CategorysMapper, Categorys> implements CategorysService {
    @Autowired(required = false)
    private CategorysMapper categorysMapper;

    @Override
    public Result getCategoryList(String parentId) {
        if (parentId.equals("0")){
            //查询一级分类
            QueryWrapper<Categorys> categorysQueryWrapper = new QueryWrapper<>();
            categorysQueryWrapper.eq("parentId",0);
            List<Categorys> categorys = categorysMapper.selectList(categorysQueryWrapper);
            return new Result(0,categorys);
        }else {
            QueryWrapper<Categorys> categorysQueryWrapper = new QueryWrapper<>();
            categorysQueryWrapper.eq("parentId",1);
            List<Categorys> categorys = categorysMapper.selectList(categorysQueryWrapper);
            return new Result(0,categorys);
        }
    }
}
